package com.example.seataxa.storage.service.impl;

import com.example.seataxa.storage.service.StorageService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 季舟
 * @Date 2024-09-14 15:28
 */
@Service
public class StorageServiceImpl implements StorageService {
    @Resource
    private JdbcTemplate jdbcTemplate;

    /**
     * 扣减库存
     *
     * @param commodityCode 商品编号
     * @param count         扣减数量
     */
    @Override
    @Transactional
    public void deduct(String commodityCode, int count) {
        jdbcTemplate.update("update stock_tbl set count = count - ? where commodity_code = ?",
                count, commodityCode);
    }

}
